/* 
 * $Id$
 *
 * UMKC Robotics 2009
 *
 * This is the driver for the stdout device.
**/

#if defined(WITH_IOSTDOUT)

#include <stdio.h>

#include "err.h"
extern int err;

#include "iobase.h"
#include "iopublic.h"
extern BotDevice bdev[];

#include "iostdout.h"

#if defined(WITH_AVRLIBC)
inline int stdout_write(char c, FILE* f) {

  return( err = E_NO_WRITE_CALLBACK );

}
#else
inline int stdout_write() {

  return( err = E_NO_ERROR );

}
#endif


inline int stdout_init() {

#if defined(WITH_AVRLIBC)
  fdev_setup_stream(&bdev[BSTDOUT].dev, 
                    stdout_write, NULL,
                    _FDEV_SETUP_WRITE );
#else
  bdev[BSTDOUT].dev = stdout;
#endif
  return( err = E_NO_ERROR);
}


inline int stdout_destroy() {

#if defined(WITH_AVRLIBC)
  fdev_close();  /* this seems broken in avrlibc */
#else
  bdev[BSTDOUT].dev = NULL;
#endif
  return( err = E_NO_ERROR);
}

inline int stdout_reset() {

  stdout_destroy();
  stdout_init();
  return( err = E_NO_ERROR);

}


#endif /* end ifdef WITH_IOSTDOUT */
